﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class service_mmbh : System.Web.UI.Page
{
    protected string tShowSuccess = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            if (Session["username"] != null && Session["userpwd"] != null)
            {
                string userName = Session["username"].ToString();
                string userpwd = Session["userpwd"].ToString();
                Bind(userName, userpwd);
                //Session["username"] = "em828871";
                //Session["userpwd"] = "888888";
                hidName.Value = userName;
                //Bind("em828871", "888888");
                Panel4.Visible = true;
                Panel1.Visible = false;
                Panel2.Visible = false;
                Panel3.Visible = false;
                pnResult.Visible = false;
                Panel5.Visible = false;
                Panel6.Visible = false;
                Panel7.Visible = false;

            }
            else
            {
                Response.Redirect("service_self.aspx");
            }
        }
    }

    protected void Bind(string uname, string pwd)
    {
        FeeDBWS.FeeDBWS feedb = new FeeDBWS.FeeDBWS();
        DataSet ds = feedb.GetPwdByParam(0, uname, uname, "");
        BakcPwd backpwd = null;


        foreach (DataRow dr in ds.Tables[0].Rows)
        {
            backpwd = new BakcPwd();
            backpwd.Email = Tools.GetString(dr["email"]);
            backpwd.Tel = Tools.GetString(dr["tel"]);
            backpwd.Question = Tools.GetString(dr["question"]);
            backpwd.Answer = Tools.GetString(dr["answer"]);
        }
        if (backpwd != null)
        {
            if (!string.IsNullOrEmpty(backpwd.Tel))
            {
                dbTel.Visible = false;
                changeTel.Visible = true;
                yztel.InnerHtml = "<img src=\"images/ico_ok.jpg\" />&nbsp;已验证，手机号码:" + backpwd.Tel;
            }
            if (!string.IsNullOrEmpty(backpwd.Email))
            {
                dbemail.Visible = false;
                changeE.Visible = true;
                yzemail.InnerHtml = "<img src=\"images/ico_ok.jpg\" />&nbsp;已验证，邮箱:" +  "****" + backpwd.Email.Substring(backpwd.Email.IndexOf('@'), backpwd.Email.Length - backpwd.Email.IndexOf('@'));
            }
            if (!string.IsNullOrEmpty(backpwd.Question))
            {
                dbQuestion.Visible = false;
                changeQ.Visible = true;
                yzquestion.InnerHtml = "<img src=\"images/ico_ok.jpg\" />&nbsp;已验证";
            }
        }
        else
        {
            dbTel.Visible = true;
            changeTel.Visible = false;
            dbemail.Visible = true;
            changeE.Visible = false;
            dbQuestion.Visible = true;
            changeQ.Visible = false;
            yztel.InnerHtml = "未验证";
            yzemail.InnerHtml = "未验证";
            yzquestion.InnerHtml = "未验证";
        }
    }
    /// <summary>
    /// 手机绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void imgbtnOk_Click(object sender, ImageClickEventArgs e)
    {
        string userName = Session["username"].ToString();
        string userpwd = Session["userpwd"].ToString();
        string code = (string)Session["code"];
        if (code.Trim() == txtCode.Text.Trim())
        {
            string tel = txtReNewTel.Text.Substring(0, 3) + "****" + txtReNewTel.Text.Substring(7, 4);
            FeeDBWS.FeeDBWS feedb = new FeeDBWS.FeeDBWS();
            try
            {
                if ((feedb.InsertOrUpdateBack(1, userName, txtReNewTel.Text, tel, "")) > 0)
                {
                    tShowSuccess = "<li class=\"coffee font14 font-weight\">您绑定的手机号码为" + tel + "</li>";
                    pnResult.Visible = true;
                    Panel4.Visible = false;
                    Panel2.Visible = false;
                    Panel3.Visible = false;
                    Panel1.Visible = false;
                    Panel5.Visible = false;
                    Panel6.Visible = false;
                    Panel7.Visible = false;
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "a", "alert('手机绑定失败，请重试');", true);
                }
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(GetType(), "a", "alert('服务器忙，请重试');", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "a", "alert('验证码不正确');", true);
        }
    }
    /// <summary>
    /// 邮箱绑定
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btn_Eok_Click(object sender, ImageClickEventArgs e)
    {
        string userName = Session["username"].ToString();
        string userpwd = Session["userpwd"].ToString();
        string code = (string)Session["code"];
        if (code.Trim() == txtECode.Text.Trim())
        {
            try
            {
                FeeDBWS.FeeDBWS feedb = new FeeDBWS.FeeDBWS();
                if ((feedb.InsertOrUpdateBack(2, userName, "", txtReEmail.Text.Trim(), "")) > 0)
                {
                    tShowSuccess = "<li class=\"coffee font14 font-weight\">您绑定的邮箱为" + txtReEmail.Text + "</li>";
                    pnResult.Visible = true;
                    Panel4.Visible = false;
                    Panel2.Visible = false;
                    Panel3.Visible = false;
                    Panel1.Visible = false;
                    Panel5.Visible = false;
                    Panel6.Visible = false;
                    Panel7.Visible = false;
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "a", "alert('邮箱绑定失败，请重试');", true);
                }
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(GetType(), "a", "alert('服务器忙，请重试');", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "a", "alert('验证码不正确');", true);
        }
    }

    protected void imgbtnQuestion_Click(object sender, ImageClickEventArgs e)
    {
        string userName = Session["username"].ToString();
        string userpwd = Session["userpwd"].ToString();
        string code = (string)Session["code"];
        if (code.Trim() == txt8.Text.Trim())
        {
            try
            {
                FeeDBWS.FeeDBWS feedb = new FeeDBWS.FeeDBWS();
                if ((feedb.InsertOrUpdateBack(3, userName, "", txtAnswer.Text, ddlQuestion.SelectedValue)) > 0)
                {
                    tShowSuccess = "<li class=\"coffee font14 font-weight\">您绑定的密保问题为&ldquo;" + ddlQuestion.SelectedValue + "&ldquo;</li><li class=\"coffee font14 font-weight\">答案为：&ldquo;" + txtAnswer.Text + "&ldquo;</li>";
                    pnResult.Visible = true;
                    Panel4.Visible = false;
                    Panel2.Visible = false;
                    Panel3.Visible = false;
                    Panel1.Visible = false;
                    Panel5.Visible = false;
                    Panel6.Visible = false;
                    Panel7.Visible = false;
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "a", "alert('密保问题绑定失败，请重试');", true);
                }
            }
            catch (Exception)
            {
                ClientScript.RegisterStartupScript(GetType(), "a", "alert('服务器忙，请重试');", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "a", "alert('验证码不正确');", true);
        }
    }
    protected void ddlQuestion_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.hidQuestion.Value = ddlQuestion.SelectedValue;
    }
    protected void dbTel_Click(object sender, ImageClickEventArgs e)
    {
        Panel4.Visible = false;
        Panel1.Visible = true;
        Panel2.Visible = false;
        Panel3.Visible = false;
        Panel5.Visible = false;
        Panel6.Visible = false;
        Panel7.Visible = false;
    }
    protected void dbemail_Click(object sender, ImageClickEventArgs e)
    {
        Panel4.Visible = false;
        Panel2.Visible = true;
        Panel3.Visible = false;
        Panel1.Visible = false;
        Panel5.Visible = false;
        Panel6.Visible = false;
        Panel7.Visible = false;
    }
    protected void dbQuestion_Click(object sender, ImageClickEventArgs e)
    {
        Panel4.Visible = false;
        Panel3.Visible = true;
        Panel2.Visible = false;
        Panel1.Visible = false;
        Panel5.Visible = false;
        Panel6.Visible = false;
        Panel7.Visible = false;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Hidden1.Value = DropDownList1.SelectedValue;
    }
    protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
    {
        string userName = Session["username"].ToString();
        string userpwd = Session["userpwd"].ToString();
        string code = (string)Session["code"];
        if (code.Trim() == txtUTCode.Text.Trim())
        {
            FeeDBWS.FeeDBWS feedb = new FeeDBWS.FeeDBWS();
            DataSet ds = feedb.GetPwdByParam(1, userName, txtUTel.Text, "");
            if (ds != null)
            {
                string tel = txtUReTel.Text.Substring(0, 3) + "****" + txtUReTel.Text.Substring(7, 4);
                if ((feedb.InsertOrUpdateBack(1, userName, txtUReTel.Text, tel, "")) > 0)
                {
                    tShowSuccess = "<li class=\"coffee font14 font-weight\">您绑定的手机号码为" + txtUReTel.Text + "</li>";
                    pnResult.Visible = true;
                    Panel4.Visible = false;
                    Panel2.Visible = false;
                    Panel3.Visible = false;
                    Panel1.Visible = false;
                    Panel5.Visible = false;
                    Panel6.Visible = false;
                    Panel7.Visible = false;
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "a", "alert('手机绑定失败，请重试');", true);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "a", "alert('原手机号码不正确，请重试');", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "a", "alert('验证码不正确');", true);
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        string userName = Session["username"].ToString();
        string userpwd = Session["userpwd"].ToString();
        string code = (string)Session["code"];
        if (code.Trim() == txtUECode.Text.Trim())
        {
            BakcPwd backpwd = null;
            FeeDBWS.FeeDBWS feedb = new FeeDBWS.FeeDBWS();
            DataSet ds = feedb.GetPwdByParam(0, userName, userName, "");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                backpwd = new BakcPwd();
                backpwd.Email = Tools.GetString(dr["email"]);
            }
            if (backpwd.Email.Trim() == txtUEOldEmail.Text.Trim())
            {
                if ((feedb.InsertOrUpdateBack(2, userName, "", txtUReEmail.Text, "")) > 0)
                {
                    tShowSuccess = "<li class=\"coffee font14 font-weight\">您绑定的邮箱为" + txtUReEmail.Text + "</li>";
                    pnResult.Visible = true;
                    Panel4.Visible = false;
                    Panel2.Visible = false;
                    Panel3.Visible = false;
                    Panel1.Visible = false;
                    Panel5.Visible = false;
                    Panel6.Visible = false;
                    Panel7.Visible = false;
                }
                else
                {
                    ClientScript.RegisterStartupScript(GetType(), "a", "alert('邮箱绑定失败，请重试');", true);
                }
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "a", "alert('原邮箱地址不正确，请重试');", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "a", "alert('验证码不正确');", true);
        }
    }
    protected void ImageButton3_Click(object sender, ImageClickEventArgs e)
    {
        string userName = Session["username"].ToString();
        string userpwd = Session["userpwd"].ToString();
        string code = (string)Session["code"];
        if (code.Trim() == txtUQCode.Text.Trim())
        {
            FeeDBWS.FeeDBWS feedb = new FeeDBWS.FeeDBWS();
            if ((feedb.InsertOrUpdateBack(3, userName, "", txtUQuesion.Text, DropDownList1.SelectedValue)) > 0)
            {
                tShowSuccess = "<li class=\"coffee font14 font-weight\">您绑定的密保问题为&ldquo;" + DropDownList1.SelectedValue + "&ldquo;</li><li class=\"coffee font14 font-weight\">答案为：&ldquo;" + txtUQuesion.Text + "&ldquo;</li>";
                pnResult.Visible = true;
                Panel4.Visible = false;
                Panel2.Visible = false;
                Panel3.Visible = false;
                Panel1.Visible = false;
                Panel5.Visible = false;
                Panel6.Visible = false;
                Panel7.Visible = false;
            }
            else
            {
                ClientScript.RegisterStartupScript(GetType(), "a", "alert('密保问题绑定失败，请重试');", true);
            }
        }
        else
        {
            ClientScript.RegisterStartupScript(GetType(), "a", "alert('验证码不正确');", true);
        }
    }
    protected void changeTel_Click(object sender, ImageClickEventArgs e)
    {
        Panel4.Visible = false;
        Panel2.Visible = false;
        Panel3.Visible = false;
        Panel1.Visible = false;
        Panel5.Visible = true;
        Panel6.Visible = false;
        Panel7.Visible = false;
    }
    protected void changeE_Click(object sender, ImageClickEventArgs e)
    {
        Panel4.Visible = false;
        Panel2.Visible = false;
        Panel3.Visible = false;
        Panel1.Visible = false;
        Panel5.Visible = false;
        Panel6.Visible = true;
        Panel7.Visible = false;
    }
    protected void changeQ_Click(object sender, ImageClickEventArgs e)
    {
        Panel4.Visible = false;
        Panel2.Visible = false;
        Panel3.Visible = false;
        Panel1.Visible = false;
        Panel5.Visible = false;
        Panel6.Visible = false;
        Panel7.Visible = true;
    }
}